package com.huakang.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huakang.entity.Docter;
import com.huakang.service.DocterService;
import com.huakang.utils.DocterVo;
import com.huakang.utils.ResultVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author{小熊}
 * @Date2025/1/10 22:52
 */
@RestController
@RequestMapping("/docter")
public class DocterController {

    @Autowired
    private DocterService docterService;

    @GetMapping("/getAll")
    public ResultVo getAll(@RequestParam(defaultValue = "1")Integer pageNum , @RequestParam(defaultValue = "5")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<DocterVo> list = docterService.getAll();
        PageInfo<DocterVo> pageInfo = new PageInfo<>(list);
        return ResultVo.success("查询成功",pageInfo);
    }
    @GetMapping("/getByCondition")
    public ResultVo getByCondition(@Param("dname") String dname, @Param("dename") String dename, @Param("kname") String kname){
        List<DocterVo> list =  docterService.getByCondition(dname,dename,kname);
        if(list.size() == 0){
            return ResultVo.fail("未查询到数据");
        }
        return ResultVo.success("查询成功",list);
    }
    @DeleteMapping("/delete")
    public ResultVo delete(Integer did){
        boolean flag = docterService.delete(did);
        if(flag){
            return ResultVo.success("删除成功");
        }
        return ResultVo.fail("删除失败");
    }
    @PostMapping("/add")
    public ResultVo add(@RequestBody Docter docter){
        boolean flag = docterService.add(docter);
        if(flag){
            return ResultVo.success("添加成功");
        }
        return ResultVo.fail("添加失败");
    }

    @GetMapping("/getById")
    public ResultVo getById(Integer did){
       Docter docter = docterService.getById(did);
       return ResultVo.success("查询成功",docter);
    }

    @PutMapping("/updateDoctor")
    public ResultVo updateDoctor(@RequestBody Docter docter){
        boolean flag = docterService.updateDoctor(docter);
        if(flag){
            return ResultVo.success("修改成功");
        }
        return ResultVo.fail("修改失败");
    }

    @GetMapping("/getKid")
    public ResultVo getKid(Integer kid){
        List<Docter> list = docterService.getKid(kid);
        return ResultVo.success("查询成功",list);
    }

    @GetMapping("/kidAll")
    public ResultVo kidAll(Integer kid){
        return ResultVo.success("",docterService.kidAll(kid));
    }
}
